﻿using System.Text.RegularExpressions;
using System.Collections;

namespace DylanExtensions
{
    static class ExtMethods
    {
        /// <summary>
        /// 检查一个字符串变量是否是个合法的电子邮件地址
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static bool isValidEmailAddress(this string s)
        {
            Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
            return regex.IsMatch(s);
        }

        /// <summary>
        /// 检查一个对象是否已经包含在一个对象集合或数组里
        /// </summary>
        /// <param name="o"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public static bool In(this object o, IEnumerable c)
        {
            foreach (object i in c)
            {
                if (i.Equals(o))
                {
                    return true;
                }
            }

            return false;
        }

    }
}
